package org.dey.controller;

import org.dey.entity.Result;
import org.dey.pojo.PageVo;
import org.dey.pojo.Role;
import org.dey.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    RoleService roleService;

    //    打开角色管理页面显示数据
    @PostMapping(value = "role.action/{pagecurrent}/{pagesize}")
    public PageVo<Role> rolelist(@RequestBody Role role, @PathVariable int pagecurrent, @PathVariable int pagesize){

        PageVo<Role> queryrole = roleService.queryrole(role, pagecurrent, pagesize);
        return queryrole;
    }

    //添加
    @PostMapping("role.action")
    public Result addrole(@RequestBody Role role){

        Result insertrole = roleService.insertrole(role);

        return insertrole;
    }

    //删除
    @DeleteMapping("role.action/{id}")
    public Result delrolebyid(@PathVariable int id){

        Result delrole = roleService.delrole(id);

        return delrole;
    }

    //修改先根据id查到该数据
    @GetMapping("role.action/{id}")
    public Role queryrolebyid(@PathVariable Integer id){

        Role queryrolebyid = roleService.queryrolebyid(id);

        return queryrolebyid;
    }

    //根据id修改
    @PutMapping("role.action")
    public Result updaterolebyid(@RequestBody Role role){

        Result updaterolebyid = roleService.updaterolebyid(role);

        return updaterolebyid;
    }

    //查询所有角色
    @GetMapping("roleAll.action")
    public List<Role> roleAll(){

        List<Role> queryrole = roleService.roleAll();

        return queryrole;
    }
}
